import { Component, OnInit, Input } from '@angular/core';

const greet: Array<[number, number, string]> = [
  [0, 4, '深夜好。'],
  [18, 24, '晚上好。'],
  [4, 6, '凌晨好。'],
  [6, 9, '早上好。'],
  [9, 11, '上午好。'],
  [11, 14, '中午好。'],
  [14, 18, '下午好。']
];

export class BusinessHours {
  beginTime: string; // 06:00
  endTime: string;
}

export interface IHomeHeader {
    businessHours: BusinessHours;
    address: string;
}


@Component({
  selector: 'app-home-header',
  templateUrl: './home-header.component.html',
  styleUrls: ['./home-header.component.less']
})
export class HomeHeaderComponent implements OnInit {

  @Input() data: IHomeHeader;

  // 当前时间问候语
  get currntGreet (): string {
    const date = new Date();
    const currentMinutes = date.getMinutes();
    const currentHours =  date.getHours() + (currentMinutes ? 1 : 0);
    let greetStr = '';
    for ( const item of greet) {
      const beginTime = item[0];
      const endTime = item[1];
      if ( currentHours > beginTime && currentHours <= endTime ) {
          greetStr = item[2];
          break;
      }
    }
    return greetStr;
  }

  constructor() { }

  ngOnInit() {
  }

}
